Skip to content

⚡ Bolt: Wrap-Up comebacks skip titles played in the past year before the max() look-up - #368

Merged
Randomname653 merged 1 commit into
mainfrom
bolt/comebacks-recent-prefilter
Nov 28, 2026
Merged

Randomname653 merged 1 commit into
mainfrom
bolt/comebacks-recent-prefilter

Conversation

@Randomname653

Copy link
Copy Markdown
Owner

Problem

After #360, wrapup_facts._comebacks is still the biggest single cost of a Wrap-Up. Its last-earlier-play look-up runs max(viewed_at) GROUP BY coalesce(series_title, title) over every earlier play of every title seen in the period. A member's regular artists have thousands of earlier plays each, so the query walks most of the history.

Measured on a temp DB seeded like a real install (384k music plays over 3 years, 20k film/episode plays, ANALYZE run):

  • _comebacks, week: 1.42 s median; month: 2.14 s.
  • whole build_wrapup_facts, week: 2.93 s; month: 4.66 s.

Change

A title with any play in the 365 days before the period's latest first-play cannot have a gap of 365+ days. One range scan on the existing ix_wh_user_type_viewed collects those titles, and the max() look-up runs only for the rest. Same final query and same output. The cutoff is max(first play in period) - 365d, so only titles that cannot qualify are dropped.

Measured effect / proof

  • _comebacks: week 1.42 s → 0.22 s; month 2.14 s → 0.21 s.
  • Full build_wrapup_facts: week 2.93 s → 1.81 s; month 4.66 s → 3.02 s.
  • Method: median of 3 repetitions, same process, seeded DB.

Tests

tests/test_wrapup_comebacks_index.py extended: a title played the year before is no comeback; 364 days of silence is no comeback and 366 is; titles played within the year are not passed to the max() look-up.

  • Before the change: the pin check fails (6 pass, 1 fail).
  • After: 7/7.
  • Full battery: 356/357 green. The one failure is test_enrichment_status_perf.py, which also fails on untouched main in the sandbox (SQLite 3.45.1 plan) and passes in CI.

Risk & edge cases

  • No change for titles with no play in the prior year, which is exactly the set that can be a comeback.
  • Titles with a NULL series_title use the same coalesce key in both queries.
  • The "all" period still returns early.
  • For year periods the cutoff falls near the period start, so the scan stays small.
  • It adds one cheap query, in exchange for a much smaller second one.

Duplicate check

Searched the journal, the other personas' journals, open and closed PRs for "comebacks" and "wrapup", and the last 300 commits on main. Only #360 touches this function, and this builds on it.


Generated by Claude Code

@Randomname653 Randomname653 mentioned this pull request Nov 28, 2026
@Randomname653
Randomname653 merged commit a10a72d into main Nov 28, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants